﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Markup;

namespace CWM.Client.Data
{
    public partial class EnumExtension : MarkupExtension
    {
        public enum TypeEnum
        {
            // 枚举
            OrganizationType,
            Status,
            Gender,
            InvoiceType,
            ClientStatus,
            ClientSource,
            ClientType,
            BillingMode,
            VolumetricMethod,
            UserStatus,
            PriceType,
            DateType,
            OrderStatus,
            TotalOrderStatus,
            PaymentMethod,
            InputType,
            TrackStatus,
            LabelType,
            GoodsType,
            InputDataType,
            PaymentType,
            PaymentStatus,
            BillStatus,
            MatchingMethod,
            BillType,
            TrackingSource,
            OrderCollectionStatus
        };

        public bool Optional { get; set; } = false;
        public TypeEnum? Type { get; set; }

        public EnumExtension()
        {
        }

        public EnumExtension(TypeEnum type)
        {
            this.Type = type;
        }

        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            if (this.Type != null)
            {
                EnumProvider enumProvider = new EnumProvider();
                enumProvider.Optional = this.Optional;
                var propertyInfo = enumProvider.GetType().GetProperty("" + this.Type);
                if (propertyInfo != null)
                {
                    return propertyInfo.GetValue(enumProvider);
                }
                return null;
            }
            else
            {
                return null;
            }
        }
    }
}